package com.mybatisplus.demo03;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mybatisplus.demo03.entity.SystemUser;
import com.mybatisplus.demo03.mapper.UserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoTest03 {
    @Autowired
    private UserMapper userMapper;
    @Test
    public void testSelect() {
        System.out.println(("----- selectAll method test ------"));
        SystemUser systemUser = new SystemUser();
        systemUser.setName("小哥");
        List<SystemUser> userList = userMapper.selectList(
                new QueryWrapper<SystemUser>(systemUser)
        );
        userList.forEach(System.out::println);
    }
    @Test
    public void testSelectWithEntity() {
        System.out.println(("----- selectAll method test ------"));
        List<SystemUser> userList = userMapper.selectList(
                new QueryWrapper<SystemUser>()
                        .lambda().like(SystemUser::getName, "hao")
        );
        userList.forEach(System.out::println);
    }
    @Test
    public void testInsert() {
        System.out.println(("----- selectAll method test ------"));
        SystemUser systemUser = new SystemUser();
        systemUser.setName("小哥");
        systemUser.setHomeAddress("");
        systemUser.setAge(0);
        userMapper.insert(systemUser);
    }
}
